Rustify ci/integration.sh script#6817
Conversation
ci/integration.rs
Outdated
| // FIXME: this means we can get a stale cargo-fmt from a previous run. | ||
| // | ||
| // `which rustfmt` fails if rustfmt is not found. Since we don't install | ||
| // `rustfmt` via `rustup`, this is the case unless we manually install it. Once | ||
| // that happens, `cargo install --force` will be called, which installs | ||
| // `rustfmt`, `cargo-fmt`, etc to `~/.cargo/bin`. This directory is cached by | ||
| // travis (see `.travis.yml`'s "cache" key), such that build-bots that arrive | ||
| // here after the first installation will find `rustfmt` and won't need to build | ||
| // it again. | ||
| // | ||
| //which cargo-fmt || cargo install --force |
There was a problem hiding this comment.
Is this comment outdated now: do things still run in Travis? Does Github actions have the same caching that might cause an issue here?
There was a problem hiding this comment.
Absolutely no idea. I kept the existing comments as is.
There was a problem hiding this comment.
We should remove this, as far as I know rust-lang/* CI has not been using Travis for a good while.
Would be good if one of the maintainers can double-check.
In the GHA case this is only true if we explicitly opt-in to actions cache on ~/.cargo/bin, i.e.
https://github.com/actions/cache/blob/main/examples.md#rust---cargo
Looking at https://github.com/rust-lang/rustfmt/blob/main/.github/workflows/integration.yml we don't use any caching so this should be fine.
| } | ||
|
|
||
| let output = run_command_with_output_and_env("cargo", &["test", test_args], current_dir, &env)?; | ||
| if ["build failed", "test result: FAILED."] |
There was a problem hiding this comment.
Will we get here? If tests or builds fail I assume cargo test will exit non-zero and in that case will run_command_with_output_and_env above return an Err?
There was a problem hiding this comment.
I kept the same behaviour as before: https://github.com/rust-lang/rustfmt/blob/main/ci/integration.sh#L46-L48
If the output contains one of the two strings, we return the function with 0, meaning success. Sounds super weird but that's the current behaviour.
There was a problem hiding this comment.
Btw, run_command_with_output_and_env doesn't check whether or not the command exited successfully.
There was a problem hiding this comment.
My guess is that the intention there is to skip over crates which already fails test (if the baseline fails it could be other reasons too).
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| )?; | ||
| write_file("rustfmt_check_output", &output)?; | ||
|
|
||
| run_command_with_env("cargo", &["test", test_args], current_dir, &env) |
There was a problem hiding this comment.
Don't we already run cargo test at line 118?
There was a problem hiding this comment.
Yep. But kept the exact same behaviour:
There was a problem hiding this comment.
This might catch really broken --check format where it should not have modified the source in some off chance, seems okay to keep it. Can we add a comment here to say sth to that effect? I imagine we won't be the only ones with that question reading this :)
980b07b to
0469d7c
Compare
|
Applied suggestions and fixed file creation. |
There was a problem hiding this comment.
I think I didn't read the original script carefully enough on my first review (I think most my confusion comes from things that script was already doing, sorry about that). So this review is more focused on changes in behaviour from the old script
(also Github isn't letting me resolve some of the conversations your answered? I don't see the button for it for some reason)
|
Updated! |
4d05d5e to
eeb5fe5
Compare
|
Applied suggestion. |
There was a problem hiding this comment.
Sorry for the delay. This broadly looks good to me, some nits.
@rustbot author
| INTEGRATION: ${{ matrix.integration }} | ||
| TARGET: x86_64-unknown-linux-gnu | ||
| run: ./ci/integration.sh | ||
| run: cargo run --bin ci-integration |
There was a problem hiding this comment.
Remark (not for this PR): I wonder if we should coalsce this and Diff Check into one crate, sth akin to citool on r-l/r. The benefit is that the tools could then share common logic easily.
There was a problem hiding this comment.
That's what I plan to do. But to reduce the diff, I decided to do it in multiple parts:
- Migrate shell scripts to rust
- Improve code
There was a problem hiding this comment.
Although I think I'll make one crate once I start porting the second one to not duplicate code.
| bin: &str, | ||
| args: I, | ||
| current_dir: &str, | ||
| env: &HashMap<&str, &str>, |
There was a problem hiding this comment.
Remark: thought about BTreeMap for stable iteration order but I think that might not matter
| } | ||
|
|
||
| let output = run_command_with_output_and_env("cargo", &["test", test_args], current_dir, &env)?; | ||
| if ["build failed", "test result: FAILED."] |
There was a problem hiding this comment.
My guess is that the intention there is to skip over crates which already fails test (if the baseline fails it could be other reasons too).
|
|
||
| let output = | ||
| run_command_with_output_and_env("cargo", &["fmt", "--all", "-v"], current_dir, &env)?; | ||
| println!("{}", output.output); |
There was a problem hiding this comment.
Thought (not for this PR): we might be able to help group the logs with GHA log groups
| )?; | ||
| write_file("rustfmt_check_output", &output)?; | ||
|
|
||
| run_command_with_env("cargo", &["test", test_args], current_dir, &env) |
There was a problem hiding this comment.
This might catch really broken --check format where it should not have modified the source in some off chance, seems okay to keep it. Can we add a comment here to say sth to that effect? I imagine we won't be the only ones with that question reading this :)
ci/integration.rs
Outdated
| // FIXME: this means we can get a stale cargo-fmt from a previous run. | ||
| // | ||
| // `which rustfmt` fails if rustfmt is not found. Since we don't install | ||
| // `rustfmt` via `rustup`, this is the case unless we manually install it. Once | ||
| // that happens, `cargo install --force` will be called, which installs | ||
| // `rustfmt`, `cargo-fmt`, etc to `~/.cargo/bin`. This directory is cached by | ||
| // travis (see `.travis.yml`'s "cache" key), such that build-bots that arrive | ||
| // here after the first installation will find `rustfmt` and won't need to build | ||
| // it again. | ||
| // | ||
| //which cargo-fmt || cargo install --force |
There was a problem hiding this comment.
We should remove this, as far as I know rust-lang/* CI has not been using Travis for a good while.
Would be good if one of the maintainers can double-check.
In the GHA case this is only true if we explicitly opt-in to actions cache on ~/.cargo/bin, i.e.
https://github.com/actions/cache/blob/main/examples.md#rust---cargo
Looking at https://github.com/rust-lang/rustfmt/blob/main/.github/workflows/integration.yml we don't use any caching so this should be fine.
|
Applied suggestions, I also added comments to explain the final command as well. |
Cargo.toml
Outdated
| [[bin]] | ||
| name = "ci-integration" | ||
| path = "ci/integration.rs" |
There was a problem hiding this comment.
Nit: can we move this up to be alongside the other [[bin]]s?
32e6ec5 to
1789617
Compare
As discussed on zulip.
I went the easy road: didn't create a workspace for this script, so it uses the same dependencies as the main project (although it only needs
std). It can be run withcargo run --bin ci-integration.Anyway, this is very straightforward conversion, please tell me if you'd prefer things to be different in any regard.
r? @jieyouxu